package banco;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;

import modelo.Pessoa;
import modelo.Veiculo;

public class Select {
	
	public Pessoa SelectPessoa(Connection conn, String tabela, String key, String value){
		
	     try{ 
	    	 
	    	String query = "SELECT * FROM " + tabela + " " + "where " + key + " = " + "'" + value + "'" ;
	     
	     //System.out.println(query);
	      // create the java statement
	      Statement st = conn.createStatement();
	       
	      // execute the query, and get a java resultset
	      ResultSet rs = st.executeQuery(query);
	      
	      // iterate through the java resultset
	      while (rs.next())
	      {
	    	//Pessoa temp = new Pessoa(rs.getString("nome"), rs.getString("cpf"), rs.getString("endereco"));	    	
	    	st.close();
	    	//return temp;	         
	      }
	    
	    }
	    catch (Exception e)
	    {
	      System.err.println("Got an exception! ");
	      System.err.println(e.getMessage());
	    
	    }
	     finally{
		      Conexao.FecharConexao();
	     }
		return null;
	  }
	
	public Veiculo SelectCarro(Connection conn, String tabela, String key, String modelo){
		
	     try{ 
	    	 
	    	String query = "SELECT * FROM " + tabela + " " + "where " + key + " = " + "'" + modelo + "'" ;
	     
	     //System.out.println(query);
	      // create the java statement
	      Statement st = conn.createStatement();
	       
	      // execute the query, and get a java resultset
	      ResultSet rs = st.executeQuery(query);
	      // iterate through the java resultset
	      while (rs.next())
	      {
	    	//Carro temp = new Carro(rs.getString("modelo"), rs.getString("marca"), rs.getString("placa"));  
	    	//return temp;	         
	        
	      }
	      st.close();
	      Conexao.FecharConexao();
	    }
	    catch (Exception e)
	    {
	      System.err.println("Got an exception! ");
	      System.err.println(e.getMessage());
	    }
		return null;
	  }
	
	public void BDtoObjeto(){
		
	}

		
}
